package com.person.leetcode.editor.cn;

/**
  * 883.三维形体投影面积
  * 2022-04-26 11:05:13
**/
public class Sequence_0883_ProjectionAreaOf3dShapes {
    public static void main(String[] args) {
        Solution solution = new Sequence_0883_ProjectionAreaOf3dShapes().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public int projectionArea(int[][] grid) {
        //数组下标对应正方体左下角坐标,数值为正方体数量
        //底面积为数组个数  xy
        //xz投影 同个x中的最大y
        //yz投影 同个y中的最大z

        //两次循环多余了
        int xy=0,xz=0,yz=0;

        //1.常规
//        for (int i = 0; i < grid.length; i++) {
//            int[] ints = grid[i];
//            int maxXz = 0;
//            for (int j = 0; j < ints.length; j++) {
//                if (ints[j] > maxXz){
//                    maxXz = ints[j];
//                }
//                if (ints[j] != 0){
//                    xy ++;
//                }
//            }
//            xz += maxXz;
//        }
//        for (int i = 0; i < grid[0].length; i++) {
//            int maxYz = 0;
//            for (int j = 0; j <grid.length; j++) {
//                int e = grid[j][i];
//                if (e > maxYz){
//                    maxYz = e;
//                }
//            }
//            yz += maxYz;
//        }

        //2. 因为是nxn的网格
        for (int i = 0; i < grid.length; i++) {

            int maxXz = 0,maxYz =0;
            for (int j = 0; j < grid[i].length; j++) {
                if (grid[i][j] > maxXz){
                    maxXz = grid[i][j];
                }
                if(grid[j][i] > maxYz){
                    maxYz = grid[j][i];
                }
                if (grid[i][j] != 0){
                    xy ++;
                }
            }
            xz += maxXz;
            yz += maxYz;
        }

        return xy+yz+xz == 1?0:xy+yz+xz ;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}
